/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yang
 * Date: 2022-05-07
 * Time: 14:25
 */
public class Main {
    public static int binarySearch(int[] nums, int target){
        int left = -1;
        int right = nums.length;
        while(left+1 < right) {
            int mid = left + right >> 1;
            if (nums[mid] <= target) {
                left = mid;
            } else {
                right = mid;
            }
        }
        if(nums[left] == target){
            return left;
        }
        else {
            return -1;
        }
    }
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        int index = binarySearch(arr,2);
        System.out.println(index);
    }
}
